#!/bin/bash
bin=lrcshow_${1}_install.bin
LC_ALL=C cat <<bin_eof >${bin}
#!/bin/bash
[ \$UID == 0 ] || run=sudo
if ! [ -z \$1 ] ;then
	case \$1 in
		--help)
		echo "Usage:"
		echo "	\`basename \$0\` [ directory ]"
		echo "	Will force to install lrcshow into directory."
		exit 0
		;;
		*)
		lrcdir="\$1"
		[ -d \$1 ] ||"\$run" mkdir -p \$lrcdir
		;;
	esac
else
	for dir in {/usr,/usr/locale,/opt}/lib/totem/plugins
	do
		if [ -d \$dir ];then
			lrcdir=\$dir
			break
		fi
	done
fi

while [ -z \$lrcdir ] ||! [ -d \$lrcdir ]
do
	echo "\"\${lrcdir}\" is not a right directory."
	echo -n "Please enter a NEW path(must be exist):"
	echo ""
	read lrcdir
done

while [ 1 ]
do
	echo -n "LrcShow will install to \$lrcdir [yes/no]?:"
	read ch
	case \$ch in
		[Yy][Ee][Ss]|[Yy])
		 break ;;
		[Nn][Oo]|[Nn])
		echo "LrcShow was NOT installed !" 
		 exit 0 ;;
		*) ;;
	esac
done
if [ -w $lrcdir ];then
	let cr=\$LINENO+7 ;
	LC_ALL=C tail -n +\$cr \$0 |\$run tar jxf -  -C \$lrcdir && echo "LrcShow was installed !" ;
else
	echo "You can have right to write \$lrcdir "
	exit 1
fi
exit 0
bin_eof
tar jcpf lrcshow.tar.bz2 -C ./bindir .
#LC_ALL=C cat lrcshow.tar.bz2 >>$bin
#rm -rf /tmp/test

